Ext.define('Xyh.controller.Contact', {
			extend : 'Ext.app.Controller',
			models : ['Contact'],
			stores : ['Contact'],
			views : ['contact.Contact', 'contact.Add','contact.Edit'],

			init : function() {
				this.control({
							'contact button[code]' : {
								click : this.searchContact
							},
							'contact button[action=addContact]' : {
								click : this.showAddContact
							},
							'contactadd button[action=save]' : {
								click : this.addContact
							},
							'contact gridpanel' : {
								itemdblclick : this.showUpdateWindow
							},
							'contactedit button[action=save]' : {
								click : this.updateContact
							}
						});

			},

			searchContact : function(button) {
				Ext.getCmp('contactgrid').setTitle(button.name + "列表");
				Ext.getStore('Contact').load({
							params : {
								oftype : button.code
							}

						});
			},
			showAddContact : function(button) {
				Ext.widget('contactadd');
			},
			addContact : function(button) {
				var win = button.up('window');
				var form = win.down('form').getForm();
				if (form.isValid()) {
					form.submit({
								success : function(form, action) {
									Ext.Msg.alert('OK', '添加成功');
									win.close();
									Ext.getStore('Contact').load();
									Ext.getCmp('contactgrid')
											.setTitle("全部联系公司列表");

								},
								failure : function(form, action) {
									Ext.Msg.alert('ERROR', '添加失败');
								}
							});
				}
			},
			showUpdateWindow : function(grid, record) {
				var edit = Ext.createWidget('contactedit');
				edit.down('form').loadRecord(record);
//				edit.down('combobox').setValue('tch');
//				Ext.getCmp('contacteditcombobox').setValue('tch');
				
			},
			updateContact : function(button) {
				var win = button.up('window');
				var form = win.down('form').getForm();
				if (form.isValid()) {
					form.submit({
								success : function(form, action) {
									Ext.Msg.alert('OK', '修改成功成功');
									win.close();
									Ext.getStore('Contact').load();
									Ext.getCmp('contactgrid')
											.setTitle("全部联系公司列表");
								},
								failure : function(form, action) {
									Ext.Msg.alert('ERROR', '修改失败');
								}
							});
				}
			}
		});